package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.DailyDetail;
import com.example.stock.service.DailyDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 日线监控
 */
@Component
public class DayClose15DDownMonitor implements Trigger{

    @Autowired
    DailyDataService dailyDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        DailyDetail lastTradingRankByStock = dailyDataService.getLastedDailyDetailByStock(monitor.getStock());
        if (lastTradingRankByStock == null) {
            return false;
        }

        return switch (monitor.getCategory()) {
            case "15D_UP" -> lastTradingRankByStock.getGt15d() >= 0;
            case "15D_DOWN" -> lastTradingRankByStock.getGt15d() < 0;
            case "20D_UP" -> lastTradingRankByStock.getGt20d() >= 0;
            case "20D_DOWN" -> lastTradingRankByStock.getGt20d() < 0;
            case "30D_UP" -> lastTradingRankByStock.getGt30d() >= 0;
            case "30D_DOWN" -> lastTradingRankByStock.getGt30d() < 0;
            case "60D_UP" -> lastTradingRankByStock.getGt60d() >= 0;
            case "60D_DOWN" -> lastTradingRankByStock.getGt60d() < 0;
            default -> false;
        };
    }
}
